<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:cc="http://java.sun.com/jsf/composite"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    

    <!-- INTERFACE -->
    <cc:interface>
        <cc:attribute name="bill" />
        <cc:attribute name="duplicate" />
    </cc:interface>

    <!-- IMPLEMENTATION -->
    <cc:implementation>

        <h:outputStylesheet library="css" name="pharmacypos.css" ></h:outputStylesheet>
        <div class="fiveinchbill" style="page-break-after: avoid!important;">

            <div class="institutionName">
                <h:outputLabel value="#{cc.attrs.bill.department.printingName}" />
            </div>
            <div class="institutionContact" >
                <div>
                    <h:outputLabel value="#{cc.attrs.bill.department.address}"/>
                </div>
                <div >
                    <h:outputLabel value="#{cc.attrs.bill.department.telephone1} "/>
                    <h:outputLabel value="#{cc.attrs.bill.department.telephone2}"/>
                </div>
                <div >
                    <h:outputLabel value="#{cc.attrs.bill.department.fax}"/>                                                 
                </div>
            </div>

            <div class="headingBillFiveFive" style="text-align: center;font-weight: bold;">
                <h:outputLabel value="#{sessionController.loggedUser.department.name}"   />    
                <h:outputLabel value="**Duplicate**"  rendered="#{cc.attrs.duplicate eq true}" /> 
                <h:outputLabel value="**Cancelled**"  rendered="#{cc.attrs.bill.cancelled eq true}" /> 
            </div>

            <div class="billline">
                <h:outputLabel value="---------------------------------------------------------------------------------------"   />                           
            </div>

            <div class="billDetailsFiveFive" >
                <table >
                    <tr>
                        <td style="text-align: left;" >
                            <h:outputLabel value="Date" class="billDetailsFiveFive" ></h:outputLabel>
                        </td>
                        <td style="width: 10px;"></td>
                        <td >:</td>
                        <td style="width: 5px;"></td>
                        <td>
                            <!--<h:outputLabel value=": &npsp;" ></h:outputLabel>-->
                            <h:outputLabel value="#{cc.attrs.bill.createdAt}" class="billDetailsFiveFive" >
                                <f:convertDateTime pattern="dd/MM/yy " ></f:convertDateTime>
                            </h:outputLabel>
                            <h:outputLabel value="#{cc.attrs.bill.createdAt}" class="billDetailsFiveFive">
                                <f:convertDateTime pattern="hh:mm a" ></f:convertDateTime>
                            </h:outputLabel>
                        </td>
                        <td style="width: 50px;"></td>
                        <td>
                            <h:outputLabel value="Bht No" class="billDetailsFiveFive" rendered="#{cc.attrs.bill.patientEncounter.bhtNo ne null}" style="font-size: 15px; font-weight: bold;"></h:outputLabel>
                        </td>
                        <td>
                            <h:outputLabel value=":" class="billDetailsFiveFive" rendered="#{cc.attrs.bill.patientEncounter.bhtNo ne null}" style="font-size: 15px; font-weight: bold;"></h:outputLabel>
                        </td>

                        <td>
                            <h:outputLabel class="billDetailsFiveFive" value="#{cc.attrs.bill.patientEncounter.bhtNo}" rendered="#{cc.attrs.bill.patientEncounter.bhtNo ne null}" style="font-size: 15px; font-weight: bold;"></h:outputLabel>
                        </td>

                    </tr>
                    
                    <tr>
                        <td style="text-align: left;" >
                            <h:outputLabel class="billDetailsFiveFive" value="Inv.No" ></h:outputLabel>
                        </td>
                        <td></td>
                        <td>:</td>
                        <td></td>
                        <td>
                            <!--<h:outputLabel value=": &npsp;" ></h:outputLabel>-->
                            <h:outputLabel class="billDetailsFiveFive" value="#{cc.attrs.bill.deptId}"  >
                            </h:outputLabel>
                        </td>
                        <td></td>
                        <td>
                            <h:outputLabel value="Room" class="billDetailsFiveFive" rendered="#{cc.attrs.bill.patientEncounter.currentPatientRoom.roomFacilityCharge.name ne null}"></h:outputLabel>
                        </td>
                        <td>
                            <h:outputLabel value=":" class="billDetailsFiveFive" rendered="#{cc.attrs.bill.patientEncounter.currentPatientRoom.roomFacilityCharge.name ne null}"></h:outputLabel>
                        </td>

                        <td>
                            <h:outputLabel value="#{cc.attrs.bill.patientEncounter.currentPatientRoom.roomFacilityCharge.name}" class="billDetailsFiveFive" rendered="#{cc.attrs.bill.patientEncounter.currentPatientRoom.roomFacilityCharge.name ne null}"></h:outputLabel>
                        </td>

                    </tr>                    
                    
                    <tr>
                        <td style="text-align: left;" >
                            <h:outputLabel class="billDetailsFiveFive" value="Order No" ></h:outputLabel>
                        </td>
                        <td></td>
                        <td>:</td>
                        <td></td>
                        <td>                            
                            <h:outputLabel class="billDetailsFiveFive" value="#{cc.attrs.bill.invoiceNumber}"  >
                            </h:outputLabel>
                        </td>
                        <td></td>
                        <td>

                        </td>
                        <td>
                            
                        </td>

                        <td>
                            
                        </td>

                    </tr>
                    
                    <tr>
                        <td style="text-align: left;" >
                            <h:outputLabel value="Paymentmethod" class="billDetailsFiveFive" rendered="#{cc.attrs.bill.paymentMethod ne null}"></h:outputLabel>
                        </td>
                        <td></td>
                        <td >
                            <h:outputLabel value=":" class="billDetailsFiveFive" rendered="#{cc.attrs.bill.paymentMethod ne null}"></h:outputLabel>
                        </td>
                        <td></td>
                        <td>
                            <h:outputLabel class="billDetailsFiveFive" value="#{cc.attrs.bill.paymentMethod}" rendered="#{cc.attrs.bill.paymentMethod ne null}">
                            </h:outputLabel>
                        </td>
                        <td style="width: 50px;"></td>
                        <td>
                            <h:outputLabel value="PayScheme" class="billDetailsFiveFive" rendered="#{cc.attrs.bill.paymentScheme.printingName ne null}"></h:outputLabel>
                        </td>
                        <td>
                            <h:outputLabel value=":" class="billDetailsFiveFive" rendered="#{cc.attrs.bill.paymentScheme.printingName ne null}"></h:outputLabel>
                        </td>

                        <td>
                            <h:outputLabel class="billDetailsFiveFive" value="#{cc.attrs.bill.paymentScheme.printingName}" rendered="#{cc.attrs.bill.paymentScheme.printingName ne null}"></h:outputLabel>
                        </td>

                    </tr>
                    
                    <tr>
                        <td style="text-align: left;" >
                            <h:outputLabel class="billDetailsFiveFive" value="Name" rendered="#{cc.attrs.bill.patient.person.nameWithTitle ne null}"></h:outputLabel>
                        </td>
                        <td></td>
                        <td><h:outputLabel value=":" rendered="#{cc.attrs.bill.patient.person.nameWithTitle ne null}"/></td>
                        <td></td>
                        <td colspan="5">                            
                            <h:outputLabel class="billDetailsFiveFive" value="#{cc.attrs.bill.patient.person.nameWithTitle}"  rendered="#{cc.attrs.bill.patient.person.nameWithTitle ne null}">
                            </h:outputLabel>
                        </td>
                        

                    </tr>
                    
                    <tr>
                        <td style="text-align: left;" >
                            <h:outputLabel class="billDetailsFiveFive" value="Staff Name" rendered="#{cc.attrs.bill.toStaff.person.nameWithTitle ne null}"></h:outputLabel>
                        </td>
                        <td></td>
                        <td><h:outputLabel value=":" rendered="#{cc.attrs.bill.toStaff.person.nameWithTitle ne null}"/></td>
                        <td></td>
                        <td colspan="5">                            
                            <h:outputLabel class="billDetailsFiveFive" value="#{cc.attrs.bill.toStaff.person.nameWithTitle}"  rendered="#{cc.attrs.bill.toStaff.person.nameWithTitle ne null}">
                            </h:outputLabel>
                        </td>
                        

                    </tr>
                    


                    <h:panelGroup rendered="#{cc.attrs.bill.toDepartment ne null}" >
                        <tr>
                            <td style="text-align: left;" >
                                <h:outputLabel value="To Unit" ></h:outputLabel>
                            </td>
                            <td></td>
                            <td>:</td>
                            <td></td>
                            <td>
                                <h:outputLabel value="#{cc.attrs.bill.toDepartment.name}"  >
                                </h:outputLabel>
                            </td>
                            <td></td>
                            <td>
                            </td>
                            <td>
                            </td>
                            <td>
                            </td>
                        </tr>
                    </h:panelGroup>

                    <h:panelGroup rendered="#{cc.attrs.bill.toInstitution ne null}" >
                        <tr>
                            <td style="text-align: left; font-size: 12px;" >
                                <h:outputLabel value="Company" style="font-size: 12px;"></h:outputLabel>
                            </td>
                            <td></td>
                            <td>:</td>
                            <td></td>
                            <td>
                                <h:outputLabel value="#{cc.attrs.bill.toInstitution.name}"  style="font-size: 12px;">
                                </h:outputLabel>
                            </td>
                            <td></td>
                            <td>
                            </td>
                            <td>
                            </td>
                            <td>
                            </td>
                        </tr>
                    </h:panelGroup>
                </table>


            </div>


            <div class="billline">
                <h:outputLabel value="---------------------------------------------------------------------------------------"   />                           
            </div>


            <div class="itemHeadingsFiveFive" >

                <table width="100%" style="width: 100%;" >
                    <tr>
                        <td style="width:45%!important;">
                            <h:outputLabel value="ITEM" styleClass="itemHeadingsFiveFive" ></h:outputLabel>
                        </td>
                        <td  style="width:5%!important;text-align: right; padding-right: 10px!important">
                            <h:outputLabel value="QTY"  styleClass="itemHeadingsFiveFive" ></h:outputLabel>
                        </td>

                        <td  style="width:10%!important;text-align: right; padding-right: 10px!important">
                            <h:outputLabel value="RATE"  styleClass="itemHeadingsFiveFive" ></h:outputLabel>
                        </td>

                        <td  style="width:10%!important;text-align: right; padding-right: 30px!important">
                            <h:outputLabel value="VALUE"  styleClass="itemHeadingsFiveFive" ></h:outputLabel>
                        </td>

                    </tr>

                    <tr>
                        <td colspan="4" style="text-align: center;" >
                            <h:outputLabel value="---------------------------------------------------------------"   />                           
                        </td>
                    </tr>
                    
                    <h:panelGroup rendered="#{cc.attrs.bill.margin > 0? 'false':'true'}">
                    <ui:repeat value="#{cc.attrs.bill.billItems}" var="bip"   >
                        <tr>
                            <td  style="overflow: visible;">
<!--                                <h:outputLabel value="#{bip.item.code}"  style="text-transform: capitalize;" >
                                </h:outputLabel>
                                -
                                &nbsp;-->
                                <h:outputLabel class="itemsBlockRightFiveFive" value="#{bip.searialNo+1} - #{bip.item.name}"  style="text-transform: capitalize!important;"  >
                                </h:outputLabel>
                            </td>
                            <td>
                                <h:outputLabel class="itemsBlockRightFiveFive"    value="#{bip.qty}"     style="text-align: right;" >
                                    <f:convertNumber integerOnly="true" />
                                </h:outputLabel>
                            </td>
                            <td    style="text-align: right;" >
                                <h:outputLabel class="itemsBlockRightFiveFive"    value="#{bip.netValue/bip.qty}"     >
                                    <f:convertNumber pattern="#,##0.00" />
                                </h:outputLabel>
                            </td>
                            <td style="text-align: right;" >
                                <h:outputLabel class="itemsBlockRightFiveFive"   value="#{bip.netValue}"    >
                                    <f:convertNumber pattern="#,##0.00" />
                                </h:outputLabel>
                            </td>

                        </tr>

                    </ui:repeat>
                    </h:panelGroup>
                    
                    <h:panelGroup rendered="#{cc.attrs.bill.margin ne 0.0}">
                    <ui:repeat value="#{cc.attrs.bill.billItems}" var="bip"   >
                        <tr>
                            <td  style="overflow: visible;">
<!--                                <h:outputLabel value="#{bip.item.code}"  style="text-transform: capitalize;" >
                                </h:outputLabel>
                                -
                                &nbsp;-->
                                <h:outputLabel class="itemsBlockRightFiveFive" value="#{bip.searialNo+1} - #{bip.item.name}"  style="text-transform: capitalize!important;"  >
                                </h:outputLabel>
                            </td>
                            <td>
                                <h:outputLabel class="itemsBlockRightFiveFive"    value="#{bip.qty}"     style="text-align: right;" >
                                    <f:convertNumber integerOnly="true" />
                                </h:outputLabel>
                            </td>
                            <td    style="text-align: right;" >
                                <h:outputLabel class="itemsBlockRightFiveFive"    value="#{bip.rate+(bip.marginValue/bip.qty)}">
                                    <f:convertNumber pattern="#,##0.00" />
                                </h:outputLabel>
                            </td>
                            
                            <td style="text-align: right;" >
                                <h:outputLabel class="itemsBlockRightFiveFive"   value="#{bip.netValue}"    >
                                    <f:convertNumber pattern="#,##0.00" />
                                </h:outputLabel>
                            </td>

                        </tr>
                    </ui:repeat>
                    </h:panelGroup>




                </table>


            </div>


            <div class="billline">
                <h:outputLabel value="---------------------------------------------------------------------------------------"   />                           
            </div>



            <div  >

                <table style="width: 100%;">

                    <h:panelGroup rendered="#{cc.attrs.bill.margin > 0? 'false':'true'}">
                    <tr>
                        <td class="totalsBlock" style="text-align: left; width: 60%;">
                            <h:outputLabel value="Total" style="font-size: 15px; font-weight: bold;"/>
                        </td>
                        <td  class="totalsBlock" style="text-align: right!important; width: 40%; padding-right: 30px;">
                            <h:outputLabel value="#{cc.attrs.bill.total}" style="font-size: 15px; font-weight: bold;">
                                <f:convertNumber pattern="#,##0.00" />
                            </h:outputLabel>
                        </td>
                    </tr>
                    </h:panelGroup>
                    
                    <h:panelGroup rendered="#{cc.attrs.bill.margin ne 0.0}">
                    <tr>
                        <td class="totalsBlock" style="text-align: left; width: 60%;">
                            <h:outputLabel value="Total" style="font-size: 15px; font-weight: bold;"/>
                        </td>
                        <td  class="totalsBlock" style="text-align: right!important; width: 40%; padding-right: 30px;">
                            <h:outputLabel value="#{cc.attrs.bill.netTotal}" style="font-size: 15px; font-weight: bold;">
                                <f:convertNumber pattern="#,##0.00" />
                            </h:outputLabel>
                        </td>
                    </tr>
                    </h:panelGroup>
                    
                    <h:panelGroup rendered="#{cc.attrs.bill.discount ne 0.0}">
                    <tr>
                        <td  class="totalsBlock" style="text-align: left;">
                            <h:outputLabel  rendered="#{cc.attrs.bill.discount ne 0.0}" value="Discount " style="font-weight: bolder!important;"/>
                        </td>
                        <td  class="totalsBlock" style="text-align: right!important; ; padding-right: 30px;">
                            <h:outputLabel rendered="#{cc.attrs.bill.discount ne 0.0}"   value="#{-cc.attrs.bill.discount}" style="font-weight: bolder!important;" >
                                <f:convertNumber pattern="#,##0.00" />
                            </h:outputLabel>
                        </td>
                    </tr>
                    </h:panelGroup>
                    
                    <tr>
                        <td  class="totalsBlock" style="text-align: left;">
                            <h:outputLabel  rendered="#{cc.attrs.bill.discount ne 0.0}"    value="Net Total" />
                        </td>
                        <td  class="totalsBlock" style="text-align: right!important;font-weight: bold; ; padding-right: 30px; ">
                            <h:outputLabel  rendered="#{cc.attrs.bill.discount ne 0.0}"    value="#{cc.attrs.bill.netTotal}">
                                <f:convertNumber pattern="#,##0.00" />
                            </h:outputLabel>
                        </td>
                    </tr>

                    <tr>
                        <td class="totalsBlock" style="text-align: left; width: 60%;">
                            <h:outputLabel value="Balance" />
                        </td>
                        <td  class="totalsBlock" style="text-align: right!important; width: 40%; padding-right: 30px;">
                            <h:outputLabel value="#{cc.attrs.bill.cashPaid-cc.attrs.bill.netTotal}" >
                                <f:convertNumber pattern="#,##0.00" />
                            </h:outputLabel>
                        </td>
                    </tr>
                    
<!--                    <tr>
                        <td class="totalsBlock" style="text-align: left; width: 60%;">
                            <h:outputLabel value="Price Matrix" />
                        </td>
                        <td  class="totalsBlock" style="text-align: right!important; width: 40%; padding-right: 30px;">
                            <h:outputLabel value="#{cc.attrs.bill.margin}" >
                                <f:convertNumber pattern="#,##0.00" />
                            </h:outputLabel>
                        </td>
                    </tr>-->

                    <tr>
                        <td  class="totalsBlock" style="text-align: left;">
                            <h:outputLabel   value="Number of Items Count" />
                        </td>
                        <td  class="totalsBlock">
                            <h:outputLabel   value="#{cc.attrs.bill.billItems.size()}">
                                <f:convertNumber pattern="#,##0.00" />
                            </h:outputLabel>
                        </td>
                    </tr>


                </table>

            </div>
            
            <div style="text-decoration: overline; margin-top: 20px;">
                <h:outputLabel value="Cashier : #{cc.attrs.bill.creater.code}"/>
            </div>

            <div class="footer" style="text-align: center;">
                <br/>
                <h:outputLabel value="#{sessionController.userPreference.pharmacyBillFooter}"/>
                <br/>
            </div>

            


        </div>
    </cc:implementation>
</html>